<template>
  <!-- 确认收货 -->
  <el-dialog
    title="确定收货"
    v-model="visible"
    width="35%"
    destroy-on-close
    @closed="$emit('closed')"
  >
    <el-form
      :model="form"
      ref="comfirnForm"
      label-width="auto"
      label-position="right"
    >
      <el-form-item label="附件">
        <sc-upload-file
          v-model="form.otherFileList"
          :limit="10"
          :multiple="false"
          tip="最多上传10个文件,单个文件不要超过20M"
        >
          <el-button type="primary" plain icon="el-icon-upload"
            >上传附件</el-button
          >
        </sc-upload-file>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" :loading="isSaveing" @click="submit()"
        >确 定</el-button
      >
    </template>
  </el-dialog>
</template>

<script>

export default {
  emits: ['success'],
  data () {
    return {
      visible: false,
      isSaveing: false,
      //表单数据
      form: {
        id: '',
        otherFileList: [],
      },

    }
  },

  mounted () {

  },
  methods: {
    //显示
    open (data) {
      this.visible = true
      this.form.id = data.id
    },
    //表单提交方法
    submit () {
      this.$refs.comfirnForm.validate(async (valid) => {
        if (valid) {
          let fileType = ''
          this.form.otherFileList.map(item => {
            if (item.url) {
              let arr = item.url.split('.')
              let type = arr[arr.length - 1]
              // fileType  1图片 2文件
              let imageType = 'jpg/png/jpeg/svg'
              if (imageType.includes(type)) {
                fileType = 1
              } else {
                fileType = 2
              }
              item.fileType = fileType
              item.fileName = item.name
            }
          })
          console.log(this.form)
          this.isSaveing = true
          let res = await this.$API.produce.deliver.updateStatus.post(this.form)
          this.isSaveing = false
          if (res.code == 200) {
            this.$emit('success', this.form, this.mode)
            this.visible = false
            this.$message.success("操作成功")
          }
        }
      })
    },

  }
}
</script>

